package main

import (
	"fmt"
	"time"
)

type User struct {
	Name string
	Age  int
}

func fooA() {
	start := time.Now()
	var c = make(chan User, 1024)
	for i := 0; i < 1024; i++ {
		user := User{Name: "zhanglin", Age: 25}
		c <- user
	}
	since := time.Since(start)
	fmt.Println(since.Milliseconds())
}

func fooB() {
	start := time.Now()
	var c = make(chan *User, 1024)
	for i := 0; i < 1024; i++ {
		user := &User{Name: "zhanglin", Age: 25}
		c <- user
	}
	since := time.Since(start)
	fmt.Println(since.Nanoseconds())
}

func main() {
	fooA()
	fooB()
}

//FooB 传递的指针，但其性能会差一些。这是由于其 New 出来的 &User 逃逸到堆上，垃圾回收导致的
//值传递 VS 指针传递
//先根据你的目的：
//你想保证参数不被修改 - 值传递
//参数结构很大 - 指针传递
